//
//  ByViewGoodsClassdifyInfo.m
//  mijifen_ios
//
//  Created by mc on 2017/11/14.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewGoodsClassdifyInfo.h"
@interface ByViewGoodsClassdifyInfo()<UITableViewDelegate,UITableViewDataSource>
@end

@implementation ByViewGoodsClassdifyInfo
{
    UITableView *_contentTable;
    NSInteger   _selectIndex;
}
- (instancetype)init{
    if (self = [super init]) {
        self.popMode = ZKBombPopModeBottom;
        self.positionMode = ZKBombPositionModeBottom;
        self.damping = 0.6;
        self.aniDuration = 0.8;
        [self setContentViews];
    }
    return self;
}

- (void)setContentViews{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 240)];
    [self addSubview:bgView];
    _contentTable = [[UITableView alloc] init];
    [bgView addSubview:_contentTable];
    _contentTable.frame = CGRectMake(0, 0, SCREEN_WIDTH, 200);
    _contentTable.delegate = self;
    _contentTable.dataSource = self;
    _contentTable.backgroundColor = [UIColor whiteColor];
    
    UIButton *sureButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, 40)];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [sureButton setBackgroundColor:BY_THEME_COLOR];
    [bgView addSubview:sureButton];
    bgView.backgroundColor = [UIColor whiteColor];
    [sureButton addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside];
    self.contentView = bgView;
}

- (void)setClassifyAry:(NSMutableArray *)classifyAry{
    _classifyAry = classifyAry;
    [_contentTable reloadData];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _classifyAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentier];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.font = FONT(16);
    }
    ByModelGoodsClassifyCate *cate_model = _classifyAry[indexPath.row];
    cell.textLabel.text = cate_model.name;
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    _selectIndex = indexPath.row;
}

#pragma mark - 确定
- (void)sureAction{
    NSLog(@"%@",_classifyAry[_selectIndex]);
    if (self.classifyBlock) {
        self.classifyBlock(_classifyAry[_selectIndex]);
    }
    [self remove];
}

@end
